package com.niuke;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * 50. 寻找最大价值的矿堆
 * https://zhuanlan.zhihu.com/p/643796636
 */
public class NiukeMoni50 {

    static List<List<Integer>> arr;
    static int n, m;

    static int[][] offsets = new int[][]{{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        arr = new ArrayList<>();
        while (scanner.hasNextLine()) {
            String line = scanner.nextLine().trim();
            if (line.length() == 0) {
                break;
            }
            List<Integer> ls = new ArrayList<>();
            for (char c : line.toCharArray()) {
                ls.add(c - '0');
            }
            arr.add(ls);//二维矩阵建图，图里存的都是整数0，1，2
        }

        n = arr.size();
        m = arr.get(0).size();

        int res = 0;

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                res = Math.max(res, dfs(i, j));
            }
        }

        System.out.println(res);
    }

    public static int dfs(int x, int y) {
        int curr = arr.get(x).get(y);
        if (curr == 0) {
            return 0;
        }

        int ans = curr;
        arr.get(x).set(y, 0);

        for (int[] offset : offsets) {
            int xx = x + offset[0];
            int yy = y + offset[1];
            if (xx >= 0 && xx < n && yy >= 0 && yy < m) {
                ans += dfs(xx, yy);
            }
        }

        return ans;
    }

}
